window.onload = function() {
    for (var i=1; i < 5; i++ ) {
        (function(k) {
        	document.getElementById("btn" + k).addEventListener("click", function() {
	            alert(k);
	        }, false);
        })(i);
    }
};

// for (var i=0; i<10; i++) {
// 	setTimeout(function() {
// 		console.log(i);
// 	}, 1000);
// }

// function foo() {
//     bar.apply(null, arguments);
//     //console.log(arguments);
// }
// function bar(a, b, c) {
//     // 내곡동에 땅이라도 산다.
//     console.log(arguments);
// }

(function() {
	var foo = 1;
})();

(function() {
	var foo = 2;
})();

var list = [1, 2, 3, 4, 5];
for(var i = 0, l = list.length; i < l; i++) {
	//console.log(list[i]);
}

for (var i in list) {
	//console.log(list[i]);
}

(function() {
	function Foo(name) {
		this.name = name;
		this.someMethod = function() {
			return this.name;
		};
	}

	var foo = new Foo('sam');

	console.log(foo.name);
	console.log(foo.someMethod());
	console.log(typeof foo !== 'undefined');
})();

(function() {
	var Foo = function(name) {
		this.name = name;
	};

	Foo.prototype.someMethod = function() {
		return this.name;
	}

	var foo = new Foo('pooh');	
	console.log(foo.name);
	console.log(foo.someMethod());
})();

(function() {
	var bar = {
		test: 12, 
		someMethod: function() {
			console.log('someMethod');
		}
	};
	
	console.log(bar.test);	
	bar.someMethod();

	console.log(typeof foo !== 'undefined');
})();


var Drama = function(name) {
	this.name = name;
};

Drama.prototype.getName = function() {
	return this.name;
};

var goldenTimes = new Drama('골든 타임즈');
console.log(goldenTimes.getName());

var whiteTower =  new Drama('하얀 거탑');
console.log(whiteTower.getName()); 


var Duck = function(weight) {
	this.weight = weight;
};

Duck.prototype = {
	swim : function() {
		console.log('swim');
	}
};

var RedDuck = function() {
	Duck.apply(this, arguments);
};

RedDuck.prototype = new Duck(400);
RedDuck.prototype.constructor = RedDuck;

RedDuck.prototype.swim();
console.log(RedDuck.prototype.weight);
console.log(RedDuck.prototype);

var MallardDuck = function() {
	Duck.apply(this, arguments);
};

MallardDuck.prototype = new Duck();
MallardDuck.prototype.constructor = MallardDuck;

function foo() {
	console.log(new Date().getSeconds());
	setTimeout(foo, 1000);
}
//foo();

//var id = setTimeout(foo, 1000);
//var id = setInterval(foo, 1000);



